import java.util.Arrays;
//插入排序
public class Java_2_001 {
    public static void main(String[] args){
        int[] arr= {9,7,8,6,5,1,3,2,4};
        insertion(arr);
        System.out.println(Arrays.toString(arr));
    }
    public static void insertion(int[] arr){
        int i,j,key;
        for(i=0;i<arr.length-1;i++){
            key=i;
            while(key>=0&&arr[key+1]<arr[key]){
                swap(arr,key,key+1);
                key--;
            }
        }
    }
    public static void swap(int[] arr,int i,int j){
        int t = arr[i];
        arr[i]=arr[j];
        arr[j]= t;
    }
}
